import Taro from '@tarojs/taro'
import app from '../../../../main.js'
let myJs = {
    getData: function() {
        this.state = {
            doctor: {
                is_open_display_order_record: '',
                is_open_inquiry_direction_order_remind: '',
                is_open_inquiry_no_direction: '',
                is_open_inquiry_direction: '',
                is_open_inquiry_group: '',
                inquiry_directional_price: '',
                inquiry_group_price: '',
            },
        };
        return this.state;
    },
    createDoctor() {
        var me = this;
        var data = me.state.doctor;
        var flag = true;
        if(me.beforeCreateDoctor) {
            flag = me.beforeCreateDoctor(data);
        }
        if(flag) {
            app.post("api/doctors/create", data, function(res) {
                if(me.afterCreateDoctor) {
                    me.afterCreateDoctor(res);
                }
            });
        }
    },
    updateDoctor() {
        var me = this;
        var data = me.state.doctor;
        var flag = true;
        if(me.beforeUpdateDoctor) {
            flag = me.beforeUpdateDoctor(data);
        }
        if(flag) {
            app.post("api/doctors/update", data, function(res) {
                if(me.afterUpdateDoctor) {
                    me.afterUpdateDoctor(res);
                }
            });
        }
    },
    getDoctor() {
        var me = this;
        var data = {id: me.state.doctor.id};
        var flag = true;
        if(me.beforeGetDoctor) {
            flag = me.beforeGetDoctor(data);
        }
        if(flag) {
            app.get("api/doctors/get", data, function(res) {
                me.setState({doctor: res.data.result});
                if(me.afterGetDoctor) {
                    me.afterGetDoctor(res);
                }
            });
        }
    },
    componentWillMount () {
        if(this.init) {
            this.init();
        }
    },
    navigateTo(url) {
        app.navigateTo(url);
    },
    handleChange(name, v) {
        console.log(name,v)
        var names = name.split('.');
        var n = names[0];
        var temp = this.state;
        for(var i = 0; i < names.length - 1; i++) {
            temp = temp[names[i]];
        }
        temp[names[i]] = v;
        this.setState({n: temp[names[i]]});
        
    },
    handleTextareaChange(name, e) {
        var names = name.split('.');
        var n = names[0];
        var temp = this.state;
        for(var i = 0; i < names.length - 1; i++) {
            temp = temp[names[i]];
        }
        temp[names[i]] = e.target.value;
        this.setState({n: temp[names[i]]});
    },
    redirectTo(url) {
        app.redirectTo(url);
    },
    componentDidMount () {},
    componentWillUnmount () {},
    componentDidHide () {}
}
export default myJs;
